package cn.edu.hit.fft;

public class Complex {
    //定义无法更改的实部和虚部
    private double real;
    private double image;

    public Complex(double re, double im) {
        this.real = re;
        this.image = im;
    }

    //定义各种运算
    public Complex addtion(Complex another) {
        Complex thisComplex = this;
        double real = thisComplex.real + another.real;
        double image = thisComplex.image + another.image;
        return new Complex(real, image);
    }

    public Complex subtraction(Complex another) {
        Complex thisComplex = this;
        double real = thisComplex.real - another.real;
        double image = thisComplex.image - another.image;
        return new Complex(real, image);
    }

    public Complex multiplication(Complex another) {
        Complex thisComplex = this;
        double real = this.real * another.real - this.image * another.image;
        double image = this.image * another.real + this.real * another.image;
        return new Complex(real, image);
    }

    public double abs() {
        return Math.hypot(this.real, this.image);
    }

    public double getReal() {
        return this.real;
    }

    public double getImage() {
        return this.image;
    }

    public void setReal(double real) {
        this.real = real;
    }

    public void setImage(double image) {
        this.image = image;
    }
}
